<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
	<title>Cadastro de Corretores</title>
</h:head>
<ui:composition template="templatePrincipal.xhtml">
	<ui:define name="header">
		<ui:include src="header.xhtml" />
	</ui:define>

	<ui:define name="centro">
		<h:body>

			<p:growl id="messages" showDetail="true" life="1000" />
			<p:confirmDialog id="confirmRemoveDialog"
				message="Remover o corretor ?" header="Remoção de corretor"
				severity="alert" widgetVar="confirmation" appendToBody="true"
				update="messages">

				<p:commandButton id="confirm" value="Sim"
					oncomplete="confirmation.hide()"
					actionListener="#{corretorController.removeCorretor}"
					update="messages,form1:tabview1:dataTable,form1:tabview1:dados" />

				<p:commandButton id="decline" value="Não"
					onclick="confirmation.hide()" type="button" />

			</p:confirmDialog>

			<h:form id="form1" prependId="false">

				<p:tabView id="tabview1" dynamic="true" cache="false">
					<p:ajax event="tabChange"
						listener="#{corretorController.changeTabView}" update="novocli" />


					<p:tab id="tabpesq" title="Pesquisar">
						<p:panelGrid columns="1" style="width:100%">

							<f:facet name="header">
        						Corretores
    							</f:facet>

							<p:panelGrid id="dados" columns="4" colspan="10"
								style="width:100%">

								<f:facet name="header">
        						Dados da pesquisa
    							</f:facet>

								<p:outputLabel for="pesqnome" value="Nome :" />
								<p:inputText id="pesqnome"
									value="#{corretorController.pesqcorretor.nome}" size="80" />

								<p:outputLabel for="pesqtel" value="Telefone :" size="14" />
								<p:inputText id="pesqtel"
									value="#{corretorController.pesqcorretor.tel}" />

								<p:outputLabel for="pesqemail" value="Email :" />
								<p:inputText id="pesqemail"
									value="#{corretorController.pesqcorretor.email}" size="40" />
								
								<p:outputLabel for="pesqtelimob" value="Telefone Imob. :" size="14" />
								<p:inputText id="pesqtelimob"
									value="#{corretorController.pesqcorretor.telImobiliaria}" />
									
								<p:outputLabel for="pesqnomeimob" value="Imobiliaria :" />
								<p:inputText id="pesqnomeimob"
									value="#{corretorController.pesqcorretor.imobiliaria}" size="80" />
								
								<p:commandButton value="Pesquisar"
									actionListener="#{corretorController.pegarTodosCorretores}"
									update="dataTable,dados" />

							</p:panelGrid>

							<p:dataTable id="dataTable" var="corretor"
								value="#{corretorController.corretorList}" paginator="true"
								rows="3"
								paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
								rowsPerPageTemplate="3,6,9"
								selection="#{corretorController.rescorretor}"
								selectionMode="single" rowKey="#{corretor.corretor_id}">

								<p:ajax event="rowSelect"
									listener="#{corretorController.rowSelect}"
									update=":form1:tabview1:dados" />


								<f:facet name="header">
            					Corretores encontrados
        					</f:facet>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Nome" />
									</f:facet>
									<h:outputText value="#{corretor.nome}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Email" />
									</f:facet>
									<h:outputText value="#{corretor.email}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Telefone" />
									</f:facet>
									<h:outputText value="#{corretor.tel}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Tel. Imob." />
									</f:facet>
									<h:outputText value="#{corretor.telImobiliaria}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Imobiliaria" />
									</f:facet>
									<h:outputText value="#{corretor.imobiliaria}" />
								</p:column>

							</p:dataTable>

							<p:panelGrid id="botoes" columns="3" colspan="10">

								<p:commandButton value="Remover" onclick="confirmation.show()"
									type="button" />

								<p:commandButton value="Salvar"
									actionListener="#{corretorController.saveCorretor}"
									update="dados,dataTable,:messages" />

								<p:commandButton value="Cancelar" type="reset" />

							</p:panelGrid>
						</p:panelGrid>

					</p:tab>

					<p:tab id="tabnovocli" title="Novo Corretor">

						<p:panelGrid id="novocli" columns="4">
							<f:facet name="header">
        					Dados do Corretor
    					</f:facet>

							<p:outputLabel for="novo_corrnome" value="Nome :" />
								<p:inputText id="novo_corrnome"
									value="#{corretorController.corretor.nome}" size="80" />

								<p:outputLabel for="novo_corrtel" value="Telefone :" size="14" />
								<p:inputText id="novo_corrtel"
									value="#{corretorController.corretor.tel}" />

								<p:outputLabel for="novo_corremail" value="Email :" />
								<p:inputText id="novo_corremail"
									value="#{corretorController.corretor.email}" size="40" />
								
								<p:outputLabel for="novo_corrtelimob" value="Telefone Imob. :" size="14" />
								<p:inputText id="novo_corrtelimob"
									value="#{corretorController.corretor.telImobiliaria}" />
									
								<p:outputLabel for="novo_corrnomeimob" value="Imobiliaria :" />
								<p:inputText id="novo_corrnomeimob"
									value="#{corretorController.corretor.imobiliaria}" size="80" />
							
							

							<p:commandButton value="Salvar"
								actionListener="#{corretorController.createCorretor}"
								update="novocli,:messages" />

							<p:commandButton value="Cancelar" type="reset" />

						</p:panelGrid>

					</p:tab>

					<p:tab tab="importar" title="Importar">
						<p:panelGrid>
							<h:outputText value="Desenvolvimento futuro" />
						</p:panelGrid>
					</p:tab>
				</p:tabView>

			</h:form>
		</h:body>
	</ui:define>
</ui:composition>
</html>